package com.zlsy.learning.leetcode.arraycorrelation.array1389;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zhouliang
 * @Date: 2020/6/24 16:54
 */
public class CreateTargetArray {

    private static int[] createTargetArray(int[] nums, int[] index) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            list.add(index[i], nums[i]);
        }
        return list.stream().mapToInt(Integer::intValue).toArray();
    }

    public static void main(String[] args) {
//        nums = [0,1,2,3,4], index = [0,1,2,2,1]
        int[] nums = new int[]{0, 1, 2, 3, 4};
        int[] index = new int[]{0,1,2,2,1};

        int[] targetArray = createTargetArray(nums, index);
        System.out.println(targetArray);
    }
}
